// 用户数据模块

export const USER_INFO = 'USER_INFO' //用户信息

export const ACCESSTOKEN = 'ACCESSTOKEN' //登录后使用的access_token

export const USERID = 'USERID' //登录后使用的userid\

export const GIRLINFO = 'GIRLINFO' //陪玩师信息

export const CHATINGINFO = 'CHATINGINFO' //对方聊天对象信息

const state = {
	userInfo: uni.getStorageSync('userInfo') || {},
	access_token: uni.getStorageSync('access_token') || '',
	
	userId: uni.getStorageSync('userId') || '',
	
	girlInfo: uni.getStorageSync('girlInfo') || '',
	
	chatingInfo: uni.getStorageSync('chatingInfo') || '',

}

const mutations = {

	[ACCESSTOKEN](state, data) {
		state.access_token = data
	},
	[USER_INFO](state, data) {
		state.userInfo = data
	},
	[USERID](state, data) {
		state.userId = data
	},
	[GIRLINFO](state, data) {
		state.girlInfo = data
	},
	[CHATINGINFO](state, data) {
		state.chatingInfo = data
	},

}

const actions = {
	//设置token 获取个人信息 并返回上次页面
	getAccesstoken({
		commit
	}, data) {
		console.log('token', data);
		setTimeout(() => {
			commit('ACCESSTOKEN', data);
		}, 10)

		uni.setStorageSync('access_token', data);
	},
	// 获取用户信息
	getUserInfo({
		commit
	}, data) {
		setTimeout(() => {
			commit('USER_INFO', data);
		}, 10)
		uni.setStorageSync('userInfo', data);
	},
	// 获取用户Id
	setUserId({
		commit
	}, data) {
		setTimeout(() => {
			commit('USERID', data);
		}, 10)
		uni.setStorageSync('userId', data);
	},
	// 获取用户Id
	setGirlInfo({
		commit
	}, data) {
		setTimeout(() => {
			commit('GIRLINFO', data);
		}, 10)
		uni.setStorageSync('girlInfo', data);
	},
	// 聊天对象
	setChatingInfo({
		commit
	}, data) {
		setTimeout(() => {
			commit('CHATINGINFO', data);
		}, 10)
		uni.setStorageSync('chatingInfo', data);
	},


}

const getters = {
	// loginFlag: state => {
	// 	return Boolean(Object.keys(state.tokenInfo).length != 0);
	// },
	// islogin: state => { //通过方法访问
	// 	if (state.userId && state.userInfo && state.userInfo.nickName) {
	// 		return true
	// 	}
	// 	return false
	// },
}

export default {
	state,
	mutations,
	actions,
	getters
}
